<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
        <script src="js/time.js?"></script>

        <script type="text/javascript">
            var i;
            var bIsInit = false;	//是否初始化了i变量

            function addp()
            {
                if (false == bIsInit)
                {
                    bIsInit = true;
                    i = <?= $num ?>;
                }

                //alert(i);

                /*
                 if (i < 4 && i >=0)
                 {
                 i++;
                 }
                 else
                 {
                 alert('can not add more items !');
                 return;
                 }
                 */
                i++; //移除之后，数据加1
                str = '<p id="p' + i + '">'
                        + '<input type="text" size="39" placeholder="<?= translate('PLASE_INPUT_ITEM') ?>"'
                        + ' name="row[item][]" id="itemid' + i + '" class="autocomplete" table="type_object" autocomplete="off" >&nbsp;&nbsp;&nbsp;'
                        + '<input type="text" size="8" placeholder="<?= translate('PLASE_INPUT_AMOUNT') ?>" name="row[amount][]" value="1" id="num' + i + '" >&nbsp;&nbsp;&nbsp;'
                        + '<select name="row[profession][]" id="profession' + i + '">'
                        + '<?php foreach ($professionlist as $m => $n) { ?>'
                        + '<option value="<?= $m ?>" ><?= $n ?></option>'
                        + '<? } ?>'
                        + '</select>'
                        + '</p>';

                $("#add").append(str);
                autocomplete();
            }
            function removep()
            {
                if (false == bIsInit)
                {
                    bIsInit = true;
                    i = <?= $num ?>;
                }

                if (i > 0)
                {
                    //alert(i);
                    $("#p" + i).remove();
                    i--;
                }
            }

        </script>

    </head>
    <body >
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <form action="" method="POST" id="rowForm">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
                <tr><td><?= translate('CDKEY_GIFTBAG_NAME') ?>:</td><td><input type='text' name="row[name]" id='name' value="<?= $row['name'] ?>"></td></tr>      	
            <!-- <tr><td><?= translate('ACTIVITY_GIFTBAG_OBJECTICON') ?>:</td><td><input type='text' name="row[objecticon]" id='objecticon' value="<?= $row['objecticon'] ?>"></td></tr>  -->
                <tr><td><?= translate('CDKEY_GIFTBAG_DESCRIBE') ?>:</td><td><textarea name="row[describe]" id="describe" rows='3' cols='25' ><?= $row['describe'] ?></textarea></td></tr>
                <tr><td><?= translate('ITEM') ?>:</td>
                    <td id="add">

                        <p id="p">                        
                            <input type="button" onclick="addp()" value="<?= translate('ADD_ONE') ?>" />
                            <input type="button" onclick="removep()" value="<?= translate('REMOVE_ONE') ?>" />
                        </p>

                        <?php for ($i = 0; $i < count($row['item']); ++$i) { ?> 
                            <p id="p<?= $i ?>">
                                <input type="text" size="39" placeholder="<?= translate('PLASE_INPUT_ITEM') ?>" name="row[item][]" id="itemid<?= $i ?>" value = '<?= $row['item'][$i] ?>' class="autocomplete" table="type_object" />&nbsp;&nbsp;
                                <input type="text" size="8"  placeholder="<?= translate('PLASE_INPUT_AMOUNT') ?>" name="row[amount][]" id="amount<?= $i ?>" value = '<?= $row['amount'][$i] ?>' />&nbsp;&nbsp;
                                <select name="row[profession][]" id="profession<?= $i ?>">	
                                    <?php foreach ($professionlist as $m => $n) { ?>                            
                                        <option value="<?= $m ?>" <?php if ($row['profession'][$i] == $m) { ?> selected="selected" <? } ?> ><?= $n ?></option>
                                    <? } ?>
                                </select>&nbsp;&nbsp;  
                            </p>  	                      	
                        <? } ?>   
                    </td>
                </tr>
                <tr><td><input type="hidden" name="row[isEver]" value="<?= $row['isEver'] ?>"></td><td><input type="submit" value="<?= translate('SUBMIT') ?>" id="submit"/> <input type="reset" value="<?= translate('RESET') ?>" id="reset"/></td></tr>
            </table>
        </form>
        <script type="text/javascript">
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                $("#name").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#usedlevel").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#weight").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#buygold").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#sellbold").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#players").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#weigh").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#odds").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#name").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#players").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#weigh").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#odds").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#name").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#players").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#weigh").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#odds").formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
                $("#starttime").formValidator({empty: false, onshow: '<?= translate('PLASE_SELECT') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#endtime").formValidator({empty: false, onshow: '<?= translate('PLASE_SELECT') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
            });
        </script>
    </body>
</html>